package cn.iocoder.yudao.module.blog.dal.mysql.jiucase;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.blog.dal.dataobject.jiucase.BlogJiuCaseDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.blog.controller.admin.jiucase.vo.*;

/**
 * 灸法案例 Mapper
 *
 * @author 曹建伟
 */
@Mapper
public interface BlogJiuCaseMapper extends BaseMapperX<BlogJiuCaseDO> {

    default PageResult<BlogJiuCaseDO> selectPage(BlogJiuCasePageReqVO reqVO) {
        if(reqVO.getToAudit() != null && reqVO.getToAudit() == true){
            return selectPage(reqVO, new LambdaQueryWrapperX<BlogJiuCaseDO>()
                    .eqIfPresent(BlogJiuCaseDO::getMemberId, reqVO.getMemberId())
                    .eqIfPresent(BlogJiuCaseDO::getShowType, reqVO.getShowType())
                    .likeIfPresent(BlogJiuCaseDO::getKeyword, reqVO.getKeyword())
                    .likeIfPresent(BlogJiuCaseDO::getTags, reqVO.getTags())
                    .betweenIfPresent(BlogJiuCaseDO::getCreateTime, reqVO.getCreateTime())
                    .eq(BlogJiuCaseDO::getLevelId, -1)
                    .orderByDesc(BlogJiuCaseDO::getId));
        }else{
            if(reqVO.getAudited() != null && reqVO.getAudited() == true){
                return selectPage(reqVO, new LambdaQueryWrapperX<BlogJiuCaseDO>()
                        .eqIfPresent(BlogJiuCaseDO::getMemberId, reqVO.getMemberId())
                        .eqIfPresent(BlogJiuCaseDO::getShowType, reqVO.getShowType())
                        .likeIfPresent(BlogJiuCaseDO::getKeyword, reqVO.getKeyword())
                        .likeIfPresent(BlogJiuCaseDO::getTags, reqVO.getTags())
                        .betweenIfPresent(BlogJiuCaseDO::getCreateTime, reqVO.getCreateTime())
                        .ge(BlogJiuCaseDO::getLevelId, 0)
                        .orderByDesc(BlogJiuCaseDO::getId));
            }

            return selectPage(reqVO, new LambdaQueryWrapperX<BlogJiuCaseDO>()
                    .eqIfPresent(BlogJiuCaseDO::getMemberId, reqVO.getMemberId())
                    .eqIfPresent(BlogJiuCaseDO::getShowType, reqVO.getShowType())
                    .likeIfPresent(BlogJiuCaseDO::getKeyword, reqVO.getKeyword())
                    .likeIfPresent(BlogJiuCaseDO::getTags, reqVO.getTags())
                    .betweenIfPresent(BlogJiuCaseDO::getCreateTime, reqVO.getCreateTime())
                    .orderByDesc(BlogJiuCaseDO::getId));
        }
    }

    default PageResult<BlogJiuCaseDO> selectAudioPage(BlogJiuCasePageReqVO reqVO){
        return selectPage(reqVO, new LambdaQueryWrapperX<BlogJiuCaseDO>()
                .eqIfPresent(BlogJiuCaseDO::getMemberId, reqVO.getMemberId())
                .eqIfPresent(BlogJiuCaseDO::getShowType, reqVO.getShowType())
                .ge(BlogJiuCaseDO::getId, reqVO.getCaseId())
                .isNotNull(BlogJiuCaseDO::getAudioUrl)
                .ne(BlogJiuCaseDO::getAudioUrl, "")
                .gt(BlogJiuCaseDO::getLevelId, -1));
    }

    default List<BlogJiuCaseDO> selectList(BlogJiuCaseExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BlogJiuCaseDO>()
                .eqIfPresent(BlogJiuCaseDO::getMemberId, reqVO.getMemberId())
                .likeIfPresent(BlogJiuCaseDO::getTags, reqVO.getTags())
                .betweenIfPresent(BlogJiuCaseDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BlogJiuCaseDO::getId));
    }

}
